import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;
public class guNa {
	
	private String splitDevanagari(String word, Map<String, String> dict) {
		String a = null;
		for(int i = 0; i <= word.length()-2; i++) {
			if(word.substring(i, i+1).equals("ो")){
				String w1 = word.substring(0, i);
				String w2 = word.substring(0, i) + "ा";
				String w3 = "उ" + word.substring(i+1);
				String w4 = "ऊ" + word.substring(i+1);
				if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}//end if
				else if(dict.containsKey(w1) && dict.containsKey(w4)){
					a = w1 + " " + w4;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w3)){
					a = w2 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w4)){
					a = w2 + " " + w4;
					return a;
				}
			}//end if
			else if(word.substring(i, i+1).equals("े")){
				String w1 = word.substring(0,i);
				String w2 = "इ" + word.substring(i+1);
				String w3 = "ई" + word.substring(i+1);
				String w4 = word.substring(0, i) + "ा";
				if((dict.containsKey(w1) && dict.containsKey(w2))){
					a = w1 + " " + w2;
					return a;
				}
				else if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w4) && dict.containsKey(w2)){
					a = w4 + " " + w2;
					return a;
				}
				else if(dict.containsKey(w4) && dict.containsKey(w3)){
					a = w4 + " " + w3;
					return a;
				}
			}//end else if
			else if(word.substring(i, i+2).equals("र्")){
				String w1 = word.substring(0, i);
				String w2 = word.substring(0, i) + "ा";
				String w3 = "ऋ" + word.substring(i+2);
				if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w3)){
					a = w2 + " " + w3;
					return a;
				}
			}
		}
		return null;
	}
	public String split(String word, Map<String, String> dict){
		String a = splitDevanagari(word, dict);
		if (a != null)
			return a;
		for(int i = 0; i < word.length()-1; i++){
			if(word.substring(i, i+1).equals("o")){
				String w1 = word.substring(0, i) + "a";
				String w2 = word.substring(0, i) + "aa";
				String w3 = "u" + word.substring(i+1);
				String w4 = "uu" + word.substring(i+1);
				if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}//end if
				else if(dict.containsKey(w1) && dict.containsKey(w4)){
					a = w1 + " " + w4;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w3)){
					a = w2 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w4)){
					a = w2 + " " + w4;
					return a;
				}
			}//end if
			else if(word.substring(i, i+1).equals("e")){
				String w1 = word.substring(0,i) + "a";
				String w2 = "i" + word.substring(i+1);
				String w3 = "ii" + word.substring(i+1);
				String w4 = word.substring(0, i) + "aa";
				if((dict.containsKey(w1) && dict.containsKey(w2))){
					a = w1 + " " + w2;
					return a;
				}
				else if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w4) && dict.containsKey(w2)){
					a = w4 + " " + w2;
					return a;
				}
				else if(dict.containsKey(w4) && dict.containsKey(w3)){
					a = w4 + " " + w3;
					return a;
				}
			}//end else if
			else if(word.substring(i, i+2).equals("ar")){
				String w1 = word.substring(0, i+1);
				String w2 = word.substring(0, i+1) + "a";
				String w3 = word.substring(i+1);
				if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w3)){
					a = w2 + " " + w3;
					return a;
				}
			}
		}//end for
		return "Word doesn't contain sandhi.";
	}//end method
}//end class
